package com.innoking.docsys.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.AbstractProcessEngineAutoConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;


/**
 * 描述:
 *
 * @author zyp
 * @description 工作流配置文件加载
 * @create 2019-09-05 8:58
 */
@Configuration
public class WorkflowConfig extends AbstractProcessEngineAutoConfiguration {

    Logger logger= LoggerFactory.getLogger(WorkflowConfig.class);

    @Bean(name = "workflowDataSource")
    @ConfigurationProperties(prefix = "spring.activiti.datasource")
    public DataSource workflowDataSource(){
        logger.info("workflowDataSource 初始化...");
        return new DruidDataSource();
    }

    @Bean
    public PlatformTransactionManager transactionManager() {
        return new DataSourceTransactionManager(workflowDataSource());
    }

    @Bean
    public SpringProcessEngineConfiguration springProcessEngineConfiguration() {
        SpringProcessEngineConfiguration configuration = new SpringProcessEngineConfiguration();
        configuration.setDataSource(workflowDataSource());
        configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        configuration.setJobExecutorActivate(true);
        configuration.setTransactionManager(transactionManager());
//        configuration.setDatabaseSchemaUpdate("create");
//        configuration.setDatabaseSchema("ACT");
        return configuration;
    }
}